package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author Pan Rundong
 * @Date 2023-03-02 21:07
 * @Desc 评论控制器
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 获取动态评论
     *
     * @param page
     * @param pagesize
     * @param movementId
     * @return org.springframework.http.ResponseEntity<com.tanhua.model.vo.PageResult>
     * @Author Pan Rundong
     */
    @GetMapping
    public ResponseEntity<PageResult> getComments(@RequestParam(defaultValue = "1") Integer page,
                                                  @RequestParam(defaultValue = "10") Integer pagesize,
                                                  String movementId)
    {
        //1.调用service
        PageResult pageResult = commentsService.getComments(page, pagesize, movementId);
        //2.返回
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论
     *
     * @param map
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @PostMapping
    public ResponseEntity publish(@RequestBody Map map) {
        //调用service
        commentsService.publish(map);
        return ResponseEntity.ok(null);
    }
}
